package Operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要借阅书籍的书名：");
        String name = scanner.nextLine();
        int current = bookList.getUsedSize();

        for (int i = 0; i < current; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name) && !book.isLend()) {
                System.out.println("借阅成功");
                book.setLend(true);
                return;
            }else if(book.isLend()){
                System.out.println("该书籍已被借出");
                return;
            }
        }
        System.out.println("该书籍不存在，借阅失败");

    }
}
